<template>
  <!-- 占位 -->
  <div
    class="placeholder"
    v-if="placeholder"
    :style="{
      height: `${navbarHeight}px`,
    }"
  ></div>

  <!-- 导航栏 -->
  <div
    class="nav-bar"
    :style="{
      height: `${navbarHeight}px`,
      paddingTop: `${statusBarHeight}px`,
      background: background,
    }"
  >
    <div
      class="left"
      :style="{
        width: `${optAreaWidth}px`,
      }"
    >
      <slot name="left">
        <div
          class="back active"
          :style="{
            width: `35px`,
            height: `${titleBarHeight}px`,
            color: backColor,
          }"
          @click="back()"
        >
          <wd-icon name="thin-arrow-left" size="18px"></wd-icon>
        </div>
      </slot>
    </div>
    <div class="title" @click="$emit('titleClick')">
      <slot name="title">
        <div class="text">{{ title }}</div>
      </slot>
    </div>
    <div
      class="right"
      :style="{
        width: `${optAreaWidth}px`,
      }"
    >
      <slot name="right" />
    </div>
  </div>
</template>

<script setup lang="ts">
import { useNavBarConfig } from '@/utils/index'
const props = defineProps({
  placeholder: {
    type: Boolean,
    default: false,
  },
  background: {
    type: String,
    default: 'transparent',
  },
  backColor: {
    type: String,
    default: '#070b1a',
  },
  title: {
    type: String,
    default: '',
  },
})

const { statusBarHeight, navbarHeight, titleBarHeight, optAreaWidth } = useNavBarConfig()

function back() {
  uni.navigateBack()
}

defineExpose({
  statusBarHeight,
  navbarHeight,
  titleBarHeight,
  optAreaWidth,
})
</script>

<style lang="scss" scoped>
.nav-bar {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 100;
  box-sizing: border-box;
  display: flex;
  align-items: center;
  width: 100%;
  .left,
  .right {
    display: flex;
    align-items: center;
    width: 100px;
    color: var(--color1);
    .back {
      display: flex;
      align-items: center;
      justify-content: center;
    }
  }
  .title {
    flex: 1;
    width: 0;
    padding: 0 10rpx;
    text-align: center;
    .text {
      overflow: hidden;
      font-size: 18px;
      font-weight: 600;
      color: var(--color1);
      text-overflow: ellipsis;
      white-space: nowrap;
    }
  }
}
</style>
